package com.flying.learning.si.sik.library;

import com.flying.learning.si.sik.library.model.Book;
import com.flying.learning.si.sik.library.model.Book.Genre;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Component
public class BookPublisher {
    private long nextBookId;

    public BookPublisher() {
        this.nextBookId = 1001L;
    }

    public List<Book> getBooks() {
        List<Book> books = new ArrayList<>();
        books.add(createFantasyBook());
        books.add(createFantasyBook());
        books.add(createFantasyBook());
        books.add(createFantasyBook());
        books.add(createFantasyBook());
        books.add(createHorrorBook());
        books.add(createHorrorBook());
        books.add(createHorrorBook());
        books.add(createHorrorBook());
        books.add(createHorrorBook());
        books.add(createRomanceBook());
        books.add(createRomanceBook());
        books.add(createRomanceBook());
        books.add(createRomanceBook());
        books.add(createRomanceBook());
        books.add(createThrillerBook());
        books.add(createThrillerBook());
        books.add(createThrillerBook());
        books.add(createThrillerBook());
        books.add(createThrillerBook());
        return books;
    }


    private Book createFantasyBook() {
        return createBook("", Genre.fantasy);
    }

    private Book createHorrorBook() {
        return createBook("", Genre.horror);
    }

    private Book createRomanceBook() {
        return createBook("", Genre.romance);
    }

    private Book createThrillerBook() {
        return createBook("", Genre.thriller);
    }

    private Book createBook(String title, Genre genre) {
        Book book = new Book();
        book.setId(nextBookId++);
        if (StringUtils.isEmpty(title)) title = "#" + book.getId();
        book.setTitle(title);
        book.setGenre(genre);
        return book;
    }
}
